package com.bf.xpdd.persistent.sqlmapdao;

import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.bf.xpdd.domain.ActivityBean;
import com.bf.xpdd.domain.ActivityGlobal;
import com.bf.xpdd.domain.ActivityRecordBean;
import com.bf.xpdd.domain.ActivitySettingBean;
import com.bf.xpdd.domain.FrontBidRecord;
import com.bf.xpdd.domain.FrontDealRecord;
import com.bf.xpdd.domain.SiteItem;
import com.bf.xpdd.persistent.iface.DaoFront;
import com.ibatis.sqlmap.client.SqlMapClient;


/**
 * DaoFrontImpl
 * @author Fantastic
 * @version 1.0.0 2011-06-25
 * @since 1.0.0
 */
@Component
public class DaoFrontImpl implements DaoFront
{

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActivityGlobal queryActivityGlobal(SqlMapClient sqlMapClient,
			String nick) throws SQLException
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nick", nick);
		
		Object result = sqlMapClient.queryForObject("front.queryActivityGlobal", map);
		if(null == result)
		{
			return null;
		}
		return (ActivityGlobal) result;
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<SiteItem> queryGobalItem(SqlMapClient sqlMapClient, String nick, int start, int end)
			throws SQLException
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nick", nick);
		map.put("start", start);
		map.put("end", end);
		return sqlMapClient.queryForList("front.queryGobalItem", map);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<FrontBidRecord> queryTop5BidRecordByAct(SqlMapClient sqlMapClient,
			String nick, String itemId) throws SQLException 
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nick", nick);
		Date date = new Date();
		map.put("month", date.getMonth() + 1);
		map.put("itemId", Long.parseLong(itemId));
 		return sqlMapClient.queryForList("front.queryTop5BidRecordByAct", map);
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<FrontDealRecord> queryTop5DealRecordByAct(SqlMapClient sqlMapClient,
			String nick, String itemId) throws SQLException 
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nick", nick);
		Date date = new Date();
		map.put("month", date.getMonth() + 1);
		map.put("itemId", Long.parseLong(itemId));
 		return sqlMapClient.queryForList("front.queryTop5DealRecordByAct", map);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActivityBean queryActivityByItem(SqlMapClient sqlMapClient, String itemId) throws SQLException
	{
		Object result = sqlMapClient.queryForObject("front.queryActivityByItem", itemId);
		if(null != result)
		{
			return (ActivityBean) result;
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActivitySettingBean queryActivitySettingByItem(
			SqlMapClient sqlMapClient, String itemId) throws SQLException 
	{
		Object result = sqlMapClient.queryForObject("front.queryActivitySettingByItem",itemId);
		if(null != result)
		{
			return (ActivitySettingBean) result;
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActivityRecordBean queryActivityRecordInfoByItem(SqlMapClient sqlMapClient, String itemId) throws SQLException 
	{
		Object result = sqlMapClient.queryForObject("front.queryActivityRecordInfoByItem", itemId);
		if(null != result)
		{
			return (ActivityRecordBean) result;
		}
		return null;
	}

}
